using System;
using Bussiness.Model.Type;
using NHibernate.Mapping.Attributes;

namespace Bussiness.Model {
    [Class(Name = "Bussiness.Model.Report, Bussiness")]
    public class Report : BaseModel {

        private string _title;
        private string _description;
        private ReportType _type = ReportType.Finalcial;
        private string _url;
        private User _uploader;
        private DateTime _uploadedDate;

        #region Constructors.
        /// <summary>
        /// No-args constructor for tools.
        /// </summary>
        public Report() { }

        /// <summary>
        /// Simple constructor
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="url"></param>
        public Report(string title, string description, string url)
        {
            _title = title;
            _description = description;
            _url = url;
        }

        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="url"></param>
        /// <param name="type"></param>
        /// <param name="uploader"></param>
        /// <param name="uploadedDate"></param>
        public Report(string title, string description, string url, ReportType type, User uploader, DateTime uploadedDate)
        {
            _title = title;
            _description = description;
            _url = url;
            _type = type;
            _uploader = uploader;
            _uploadedDate = uploadedDate;
        }

        #endregion

        [Property(NotNull = true, Length = 400)]
        public virtual string Title
        {
            get { return _title; }
            set { _title = value; }
        }

        [Property(Length = 500)]
        public virtual string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        [Property(Length = 200, NotNull = true)]
        public virtual string Url
        {
            get { return _url; }
            set { _url = value; }
        }

        [Property]
        public virtual ReportType Type
        {
            get { return _type; }
            set { _type = value; }
        }

        [ManyToOne(0, OuterJoin = OuterJoinStrategy.True, Cascade = "save-update")]
        [Column(1, Name = "USER_ID", NotNull = false)]
        public virtual User Uploader
        {
            get { return _uploader; }
            set { _uploader = value; }
        }

        [Property]
        public virtual DateTime UploadedDate
        {
            get { return _uploadedDate; }
            set { _uploadedDate = value; }
        }

        public override bool Equals(object obj)
        {
            if (obj == this) return true;
            if (!(obj is Report)) return false;
            var that = (Report)obj;
            if (this.Title != that.Title) return false;
            if (this.Description != null ? this.Description != that.Description : that.Description != null)
                return false;
            if (this.Url != that.Url) return false;

            return (this.Type == that.Type);
        }

        public override int GetHashCode()
        {
            var result = Title.GetHashCode();
            if (Description != null) result = 29 * result + Description.GetHashCode();
            result = 29 * result + Type.GetHashCode();
            result = 29 * result + Url.GetHashCode();
            return result;
        }
    }
}
